<?php  
 
    class generuj_grafy_model extends CI_Model {
 
        const G_WIDTH = 800; // 600
        const G_HEIGHT = 600; // 450
        const PIE_X = 400; // 300
        const PIE_Y = 300; // 230
        const PIE_RADIUS = 350; // 250
        const LEGEND_X = 20; // 20
        const LEGEND_Y = 550; // 400
        
        public static function generuj($grafy) {
            if (isset($grafy["grafy"])) {
                include("pChart2.1.3/class/pData.class.php");
                include("pChart2.1.3/class/pDraw.class.php");
                include("pChart2.1.3/class/pPie.class.php");
                include("pChart2.1.3/class/pImage.class.php");
                include("pChart2.1.3/class/pCache.class.php");
                    
                foreach ($grafy["grafy"] as $graf) {
                    /* Create and populate the pData object */
                    $MyData = new pData();   
                    $MyData->addPoints($graf['hodnoty'],"ScoreA");  
                    $MyData->setSerieDescription("ScoreA","Application A");

                    /* Define the absissa serie */
                    $MyData->addPoints($graf['nazvy'],"Labels");
                    $MyData->setAbscissa("Labels");

                    /* Create the pChart object */
                    $myPicture = new pImage(self::G_WIDTH,self::G_HEIGHT,$MyData,TRUE);

                    /* Draw a gradient overlay */
                    $Settings = array("StartR"=>220, "StartG"=>220, "StartB"=>220, "EndR"=>190, "EndG"=>190, "EndB"=>190, "Alpha"=>50);
                    $myPicture->drawGradientArea(0,0,self::G_WIDTH,self::G_HEIGHT,DIRECTION_VERTICAL,$Settings);
                    $myPicture->drawGradientArea(0,0,self::G_WIDTH,25,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>100));
                         
                    /* Add a border to the picture */
                    $myPicture->drawRectangle(0,0,  self::G_WIDTH - 1,self::G_HEIGHT - 1,array("R"=>0,"G"=>0,"B"=>0));
                         
                    /* Write the picture title */ 
                    $myPicture->setFontProperties(array("FontName"=>"./pChart2.1.3/fonts/calibri.ttf","FontSize"=>9));
                    $myPicture->drawText(10,20,$graf['graph_title'],array("R"=>255,"G"=>255,"B"=>255)); 
                         
                    /* Set the default font properties */ 
                    $myPicture->setFontProperties(array("FontName"=>"./pChart2.1.3/fonts/Forgotte.ttf","FontSize"=>10,"R"=>80,"G"=>80,"B"=>80));

                    /* Create the pPie object */ 
                    $PieChart = new pPie($myPicture,$MyData);

                    /* Enable shadow computing */ 
                    $myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
                         
                    /* Draw a splitted pie chart */ 
                    $PieChart->draw3DPie(self::PIE_X,self::PIE_Y,array("WriteValues"=>TRUE,"ValueR"=>0,"ValueG"=>0,"ValueB"=>0,"Radius"=>self::PIE_RADIUS,"DataGapAngle"=>6,"DataGapRadius"=>6,"Border"=>TRUE));

                    /* Write the legend box */ 
                    $myPicture->setFontProperties(array("FontName"=>"./pChart2.1.3/fonts/calibri.ttf","FontSize"=>9,"R"=>0,"G"=>0,"B"=>0));
                    $PieChart->drawPieLegend(self::LEGEND_X,self::LEGEND_Y,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

                    $myPicture->render("pictures/" . $graf['image_name']); 
                }
            }
        }
    }

?>